package ysq.xyg.web.controller;

import cn.hutool.core.util.StrUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;
import ysq.xyg.base.aspect.BaseLog;
import ysq.xyg.base.controller.BaseController;
import ysq.xyg.base.model.dto.ReturnEntity;
import ysq.xyg.base.util.BaseConstant;
import ysq.xyg.sys.model.po.SysUser;
import ysq.xyg.web.model.po.WebNavigation;
import ysq.xyg.web.model.vo.WebNavigationVo;
import ysq.xyg.web.service.WebNavigationService;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * 网站模块-网站导航controller层
 *
 * @author shengQiang yu
 * @date 2019-6-4 21:16:29
 */
@RestController
public class WebNavigationController extends BaseController {

    private static Logger log= LoggerFactory.getLogger(WebNavigationController.class);
    @Resource
    private WebNavigationService webNavigationService;

    private WebNavigation webNavigation;

    @RequestMapping("/web/*")
    public Model goPage(Model model) {
        return model;
    }

    /**
     * 列表页面
     *
     * @param useType 使用类型:1、网页端，2、移动端
     * @author shengQiang yu
     * @date 2019-4-25 16:53:29
     * */
    @RequestMapping(value="/webNavigation/listPage")
    public ModelAndView listPage(String useType){
        ModelAndView modelAndView=new ModelAndView("/web/webNavigationList");
        modelAndView.addObject("useType",useType);
        return modelAndView;
    }
    /**
     * 分页查询
     *
     * @param webNavigationVo 对象
     * @param pageSize 展示数量
     * @param pageNum 当前页面
     * @author shengQiang yu
     * @date 2019-6-4 21:16:29
     */
    @BaseLog(module = "网站模块",className = "网站导航",methods = "分页查询",businessType = BaseConstant.SYS_BUSINESS_TYPE_GET,operatorType= BaseConstant.SYS_OPERATOR_TYPE_PC)
    @RequestMapping(value = "/webNavigation/page",method = RequestMethod.POST)
    public ReturnEntity page(WebNavigationVo webNavigationVo, int pageSize, int pageNum){
        ReturnEntity returnEntity = webNavigationService.page(webNavigationVo,pageSize,pageNum);
        return returnEntity;
    }
    /**
     * 批量查询
     *
     * @param webNavigationVo 对象
     * @author shengQiang yu
     * @date 2019-4-1 10:31:20
     */
    @BaseLog(module = "网站模块",className = "网站导航",methods = "批量查询",businessType = BaseConstant.SYS_BUSINESS_TYPE_GET,operatorType= BaseConstant.SYS_OPERATOR_TYPE_PC)
    @RequestMapping(value = "/webNavigation/list",method = RequestMethod.POST)
    public ReturnEntity list(HttpServletRequest request,WebNavigationVo webNavigationVo){
        SysUser sysUser=acceptCurrentUser(request);
        webNavigationVo.setUserId(sysUser.getId());
        webNavigationVo.setRemoveTag(BaseConstant.BASE_REMOVE_TAG_NORMAL);
        ReturnEntity returnEntity = new ReturnEntity(webNavigationService.acceptList(webNavigationVo));
        return returnEntity;
    }
    /**
     * 跳转连接
     *
     * @param id 主键id
     * @author shengQiang yu
     * @date 2019-6-4 21:16:29
     */
    @RequestMapping(value = "/webNavigation/getEntity",method = RequestMethod.GET)
    public ModelAndView getEntity(String id,String parentId,String useType){
        ModelAndView view = new ModelAndView("/web/webNavigationUpdateOrSave");
        WebNavigation webNavigation=new WebNavigation();
        if(StrUtil.isNotEmpty(id)){
            webNavigation = webNavigationService.selectByPrimaryKey(id);
        }
        if(StrUtil.isNotEmpty(parentId)){
            WebNavigation parentNav = webNavigationService.selectByPrimaryKey(parentId);
            if(parentNav!=null){
                webNavigation.setParentName(parentNav.getName());
                webNavigation.setParentId(parentId);
            }
        }
        view.addObject("webNavigation", webNavigation);
        view.addObject("useType", useType);
        return view;
    }
    /**
     * 删除
     *
     * @param id 主键id
     * @author shengQiang yu
     * @date 2019-6-4 21:16:29
     */
    @BaseLog(module = "网站模块",className = "网站导航",methods = "删除",businessType = BaseConstant.SYS_BUSINESS_TYPE_DELETE,operatorType= BaseConstant.SYS_OPERATOR_TYPE_PC)
    @RequestMapping(value = "/webNavigation/delete")
    public ReturnEntity delete(HttpServletRequest request,String id){
        return webNavigationService.delete(id,acceptCurrentUser(request));
    }

    /**
     * 添加或修改
     *
     * @param webNavigationVo Vo对象
     * @author shengQiang yu
     * @date 2019-6-4 21:16:29
     */
    @BaseLog(module = "网站模块",className = "网站导航",methods = "添加或修改",businessType = BaseConstant.SYS_BUSINESS_TYPE_UPDATE,operatorType= BaseConstant.SYS_OPERATOR_TYPE_PC)
    @RequestMapping(value = "/webNavigation/addOrUpdate",method = RequestMethod.POST)
    public ReturnEntity delete(HttpServletRequest request,WebNavigationVo webNavigationVo){
        return webNavigationService.addOrUpdate(webNavigationVo,acceptCurrentUser(request));
    }
}